package com.chance.cc.crawler.development.bootstrap.zhaoshang;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpConstant;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterInfo;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2020/12/24 14:28
 * @Description
 *      招商 中标速递
 **/
public class ZhaoshangBiddingReprot {

    private static final String Cookie = "zsid=3ad74f1c-2448-45d6-a005-8e4880db78d9";

    public static void main(String[] args) {
        String domain = "zhaoshang";
        String site = "biddingReprot";
        String list = "http://zhaoshang.zkdj.com/folder/list";

        DevCrawlerController.builder()
                .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .consoleResultPipeline(site + "List")
                .consoleResultPipeline(site + "Seach")
                .consoleResultPipeline(site + "EnterpriseInfo")
                .fileResultPipeline(site + "List", "D:\\chance\\log\\zhaoshang_"+site + "List.log", false)
                .fileResultPipeline(site + "Seach", "D:\\chance\\log\\zhaoshang_"+site + "Seach.log", false)
                .fileResultPipeline(site + "EnterpriseInfo", "D:\\chance\\log\\zhaoshang_"+site+"EnterpriseInfo.log", false)
                .requestRecord(listRecord(domain,list,site))
                .build().start();

    }

    public static CrawlerRequestRecord listRecord(String domain,String url,String site){
        Proxy proxy = new Proxy();
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");

        FilterInfo countFilter = new FilterInfo();
        countFilter.setCountTotalNum(5);
        countFilter.setCurCount(0);
        countFilter.setFilter(CrawlerEnum.CrawlerRecordFilter.count);

        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .domain(domain)
                .httpUrl(url)
                .recordKey(url)
                .httpConfig(HttpConfig.me(domain))
                .needWashed(true)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .turnPageFilterInfo(countFilter)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .releaseTime(System.currentTimeMillis())
                .build();


        HttpRequest httpRequest = crawlerRequestRecord.getHttpRequest();
        httpRequest.setMethod(HttpConstant.Method.POST);
        httpRequest.addHeader("Accept"," application/json, text/javascript, */*; q=0.01");
        httpRequest.addHeader("Cookie",Cookie);
        httpRequest.addHeader("Host"," zhaoshang.zkdj.com");
        httpRequest.addHeader("Origin"," http://zhaoshang.zkdj.com");
        httpRequest.addHeader("Referer"," http://zhaoshang.zkdj.com/"+site);
        httpRequest.addHeader("User-Agent"," Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36");

        crawlerRequestRecord.tagsCreator().bizTags().addSite(site);

        return crawlerRequestRecord;
    }

}
